<template>
  <el-tree :data="departs" :props="defaultProps" :default-expand-all="true">
    <el-row slot-scope="{ data }" el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%">
      <el-col>
        <strong v-if="!ishow"><i>{{ data.name }}</i></strong>
        <span v-else>{{ data.name }}</span>
      </el-col>
      <el-col :span="4">
        <el-row type="flex" justify="end">
          <!-- 两个内容 -->
          <el-col>{{ data.manager }}</el-col>
          <el-col>
            <!-- 下拉菜单 element -->
            <el-dropdown>
              <span>
                操作<i class="el-icon-arrow-down" />
              </span>
              <!-- 下拉菜单 -->
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="add(data)">添加子部门</el-dropdown-item>
                <el-dropdown-item v-if="ishow">查看/修改部门</el-dropdown-item>
                <el-dropdown-item v-if="ishow" @click.native="deldeparments(data.id)">删除部门</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </el-tree>
</template>
<script>
import { deldepartment } from '@/api/deparment.js'
export default {
  props: {
    departs: {
      type: Array,
      required: true
    },
    ishow: {
      type: Boolean,
      required: true
    }

  },

  methods: {
    defaultProps() {
      // console.log(1)
    },
    async deldeparments(id) {
      await this.$confirm('请确认是否删除')
      await deldepartment(id)
      this.$message.success('删除成功')
      this.$emit('deldeparments')
    },
    add(data) {
      this.$emit('add', data)
      // console.log(123)
      // console.log(this.data.id)
      // adddepartment()
    }
  }
}
</script>
<style lang='less' scoped>

</style>

